Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/component/MetricCardFlow.kt 492afbde5c98f3efdcd367ab2f13ef3665fe7388 (492afbde) Text, 5.39 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.node.component

Tff7b72import T7ee787androidx.compose.foundation.layout.Arrangement
Tff7b72import T7ee787androidx.compose.foundation.layout.Column
Tff7b72import T7ee787androidx.compose.foundation.layout.FlowRow
Tff7b72import T7ee787androidx.compose.foundation.layout.IntrinsicSize
Tff7b72import T7ee787androidx.compose.foundation.layout.fillMaxWidth
Tff7b72import T7ee787androidx.compose.foundation.layout.width
Tff7b72import T7ee787androidx.compose.material3.MaterialTheme
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.ui.Modifier
Tff7b72import T7ee787androidx.compose.ui.graphics.Color
Tff7b72import T7ee787androidx.compose.ui.unit.dp
Tff7b72import T7ee787org.jetbrains.compose.resources.stringResource
Tff7b72import T7ee787org.meshtastic.core.resources.Res
Tff7b72import T7ee787org.meshtastic.core.resources.metric_channel_label
Tff7b72import T7ee787org.meshtastic.feature.node.model.DrawableMetricInfo
Tff7b72import T7ee787org.meshtastic.feature.node.model.MetricInfo
Tff7b72import T7ee787org.meshtastic.feature.node.model.VectorMetricInfo

T8b949e/** Cards that belong together — one physical sensor, or a reading and the value derived from it. */
Te6edf3internal Tff7b72typealias Te6edf3MetricGroup Tff7b72= Te6edf3ListTff7b72<Te6edf3MetricInfoTff7b72>

T8b949e/** Groups a single reading that has nothing to pair with, so it renders as a one-card column. */
Tff7b72internal Tff7b72fun Te6edf3MetricInfoTb4b4b4.Td2a8ffasGroupTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3MetricGroup Tff7b72= Te6edf3listOfTb4b4b4(Tff7b72thisTb4b4b4)

T8b949e/** Height, in cards, that a column is packed to when a run of unrelated single metrics is stacked. */
Tff7b72private Tff7b72const Tff7b72val Te6edf3PACKED_COLUMN_HEIGHT Tff7b72= T79c0ff2

T8b949e/**
* Packs runs of consecutive single-metric groups into taller columns, preserving order.
*
* A [FlowRow] row is as tall as its tallest child, so mixing one-card columns with grouped two-card columns strands
* empty space beneath every single card. Stacking consecutive singles keeps rows an even height and reclaims most of
* that space; a single sandwiched between two multi-card groups still gets a column of its own.
*/
Tff7b72private Tff7b72fun Td2a8ffListTff7b72<Te6edf3MetricGroupTff7b72>Tb4b4b4.Te6edf3packedTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3ListTff7b72<Te6edf3MetricGroupTff7b72> Tff7b72= Te6edf3buildList Tb4b4b4{
Tff7b72val Te6edf3singles Tff7b72= Te6edf3mutableListOfTff7b72<Te6edf3MetricInfoTff7b72>Tb4b4b4(Tb4b4b4)
Tff7b72fun Td2a8ffflushSinglesTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3singlesTb4b4b4.Te6edf3chunkedTb4b4b4(Te6edf3PACKED_COLUMN_HEIGHTTb4b4b4)Tb4b4b4.Te6edf3forEach Tb4b4b4{ Te6edf3addTb4b4b4(Tffa657itTb4b4b4) Tb4b4b4}
Te6edf3singlesTb4b4b4.Te6edf3clearTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tff7b72thisTf0883e@packed.filter Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3isNotEmptyTb4b4b4(Tb4b4b4) Tb4b4b4}
Tb4b4b4.Te6edf3forEach Tb4b4b4{ Te6edf3group Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3groupTb4b4b4.Te6edf3size Tff7b72=Tff7b72= T79c0ff1Tb4b4b4) Tb4b4b4{
Te6edf3singles Tff7b72+Tff7b72= Te6edf3group
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3flushSinglesTb4b4b4(Tb4b4b4)
Te6edf3addTb4b4b4(Te6edf3groupTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Te6edf3flushSinglesTb4b4b4(Tb4b4b4)
Tb4b4b4}

T8b949e/**
* Lays metric cards out as a wrapping row of vertical columns, one column per [MetricGroup].
*
* Related readings (a channel's voltage and current, a temperature and its dew point) stay stacked together and share a
* column width; unrelated single readings are packed into columns of [PACKED_COLUMN_HEIGHT] so the grid keeps an even
* height. Both together pack the cards far more tightly than a flat row of independent cards — see issue #4507.
*
* [valueColor] overrides a card's value text color, for metrics that are color-coded by severity; returning null keeps
* the [InfoCard] default.
*/
Tf0883e@Composable
Tff7b72internal Tff7b72fun Td2a8ffMetricCardFlowTb4b4b4(
Te6edf3groupsTb4b4b4: Te6edf3ListTff7b72<Te6edf3MetricGroupTff7b72>Tb4b4b4,
Te6edf3modifierTb4b4b4: Te6edf3Modifier Tff7b72= Te6edf3ModifierTb4b4b4,
Te6edf3valueColorTb4b4b4: Tb4b4b4(Te6edf3MetricInfoTb4b4b4) Tff7b72-Tff7b72> Te6edf3Color? Tff7b72= Tb4b4b4{ Tff7b72null Tb4b4b4}Tb4b4b4,
Tb4b4b4) Tb4b4b4{
Te6edf3FlowRowTb4b4b4(
Te6edf3modifier Tff7b72= Te6edf3modifierTb4b4b4.Te6edf3fillMaxWidthTb4b4b4(Tb4b4b4)Tb4b4b4,
Te6edf3horizontalArrangement Tff7b72= Te6edf3ArrangementTb4b4b4.Te6edf3SpaceEvenlyTb4b4b4,
Te6edf3verticalArrangement Tff7b72= Te6edf3ArrangementTb4b4b4.Te6edf3spacedByTb4b4b4(T79c0ff4.Te6edf3dpTb4b4b4)Tb4b4b4,
Tb4b4b4) Tb4b4b4{
Te6edf3groupsTb4b4b4.Te6edf3packedTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3forEach Tb4b4b4{ Te6edf3group Tff7b72-Tff7b72>
T8b949e// IntrinsicSize.Max + fillMaxWidth keeps every card in a column the same width as the column's widest.
Te6edf3ColumnTb4b4b4(Te6edf3modifier Tff7b72= Te6edf3ModifierTb4b4b4.Te6edf3widthTb4b4b4(Te6edf3IntrinsicSizeTb4b4b4.Te6edf3MaxTb4b4b4)Tb4b4b4, Te6edf3verticalArrangement Tff7b72= Te6edf3ArrangementTb4b4b4.Te6edf3spacedByTb4b4b4(T79c0ff4.Te6edf3dpTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3groupTb4b4b4.Te6edf3forEach Tb4b4b4{ Te6edf3metric Tff7b72-Tff7b72> Te6edf3MetricCardTb4b4b4(Te6edf3metric Tff7b72= Te6edf3metricTb4b4b4, Te6edf3valueColor Tff7b72= Te6edf3valueColorTb4b4b4(Te6edf3metricTb4b4b4)Tb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Tf0883e@Composable
Tff7b72private Tff7b72fun Td2a8ffMetricCardTb4b4b4(Te6edf3metricTb4b4b4: Te6edf3MetricInfoTb4b4b4, Te6edf3valueColorTb4b4b4: Te6edf3Color?Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3cardModifier Tff7b72= Te6edf3ModifierTb4b4b4.Te6edf3fillMaxWidthTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3label Tff7b72=
Te6edf3metricTb4b4b4.Te6edf3channelNumberTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3metric_channel_labelTb4b4b4, Te6edf3stringResourceTb4b4b4(Te6edf3metricTb4b4b4.Te6edf3labelTb4b4b4)Tb4b4b4, Tffa657itTb4b4b4) Tb4b4b4}
Tff7b72?: Te6edf3stringResourceTb4b4b4(Te6edf3metricTb4b4b4.Te6edf3labelTb4b4b4)
Tff7b72val Te6edf3resolvedValueColor Tff7b72= Te6edf3valueColor Tff7b72?: Te6edf3MaterialThemeTb4b4b4.Te6edf3colorSchemeTb4b4b4.Te6edf3onSurface
Tff7b72when Tb4b4b4(Te6edf3metricTb4b4b4) Tb4b4b4{
Tff7b72is Te6edf3VectorMetricInfo Tff7b72-Tff7b72>
Te6edf3InfoCardTb4b4b4(
Te6edf3icon Tff7b72= Te6edf3metricTb4b4b4.Te6edf3iconTb4b4b4,
Te6edf3text Tff7b72= Te6edf3labelTb4b4b4,
Te6edf3value Tff7b72= Te6edf3metricTb4b4b4.Te6edf3valueTb4b4b4,
Te6edf3rotateIcon Tff7b72= Te6edf3metricTb4b4b4.Te6edf3rotateIconTb4b4b4,
Te6edf3modifier Tff7b72= Te6edf3cardModifierTb4b4b4,
Te6edf3valueColor Tff7b72= Te6edf3resolvedValueColorTb4b4b4,
Tb4b4b4)

Tff7b72is Te6edf3DrawableMetricInfo Tff7b72-Tff7b72>
Te6edf3DrawableInfoCardTb4b4b4(
Te6edf3iconRes Tff7b72= Te6edf3metricTb4b4b4.Te6edf3iconTb4b4b4,
Te6edf3text Tff7b72= Te6edf3labelTb4b4b4,
Te6edf3value Tff7b72= Te6edf3metricTb4b4b4.Te6edf3valueTb4b4b4,
Te6edf3rotateIcon Tff7b72= Te6edf3metricTb4b4b4.Te6edf3rotateIconTb4b4b4,
Te6edf3modifier Tff7b72= Te6edf3cardModifierTb4b4b4,
Te6edf3valueColor Tff7b72= Te6edf3resolvedValueColorTb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.4.2 - Generated in 0.06s